package com.jimmy.nonweb.ext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

@Service
public class GitService {

    @Autowired
    private WebClient beijingGit;

    public Account[] fetchAccounts() {
        Account[] beijingAccounts = beijingGit.get()
                .uri(uriBuilder -> uriBuilder
                        .path("/users")
                        .queryParam("per_page", 2)
                        .queryParam("page", 1)
                        .queryParam("simple", true)
                        .build())
                .retrieve()
                .bodyToMono(Account[].class)
                .block();
        return beijingAccounts;
    }

}
